/**
 * Created by Administrator on 2017/4/6 0006.
 */
var React = require('react');
var CartIcon =require('../components/CartIcon');

module.exports = React.createClass({
    getInitialState: function () {
        return {
            goodid:'',
            goodname:'',
            goodsnum:'',
            goodimg:'',
            gooddes:'婴儿奶粉 1段适合0-6个月',
            goodprice:'',
            checked :false,
            cartList:[]
        }
    },

    componentDidMount: function () {
        if(this.props.goodid){
            this.setState({goodid:this.props.goodid});
        }
        if(this.props.goodname){
            this.setState({goodname:this.props.goodname});
        }
        if(this.props.goodsnum){
            this.setState({goodsnum:this.props.goodsnum});
        }
        if(this.props.goodimg){
            this.setState({goodimg:this.props.goodimg});
        }
        if(this.props.gooddes){
            this.setState({gooddes:this.props.gooddes});
        }
        if(this.props.goodprice){
            this.setState({goodprice:this.props.goodprice});
        }
    },

    change:function(e){
        var goods_id = e.currentTarget.getAttribute('data-id');
        console.log('good_id--------' + goods_id);
    },

  /*  change:function(e){
        if(this.state.flag == true){
            this.setState({ flag: false });
            document.getElementsByClassName('cartIcon')[0].setAttribute('src','images/bottom.png');
        } else {
            this.setState({ flag: true });
            document.getElementsByClassName('cartIcon')[0].setAttribute('src','images/top.jpg');
        }
    },*/

    render: function () {
        console.log('--id---' + this.state.goodid);
        return (
            <div className="cartListItem" onClick={this.change}  data-id={this.state.goodid}>
                <div className="cartIcon" checked={this.state.checked}></div>
                <img src={this.state.goodimg}/>
                <div className="des">
                    <p>{this.state.gooddes}</p>
                    <p>{this.state.goodname}</p>
                    <div className="num">
                        <div className="push btn"></div>
                        <p className="number">{this.state.goodsnum}</p>
                        <div className="reduce btn"></div>
                        <p className="price">
                            ¥<span>{this.state.goodprice}</span>
                        </p>
                    </div>
                </div>
            </div>
        )
    }
});
